package com.sright.bcard.mini.web.controller;

import com.sright.bcard.common.service.share.dto.request.CardTemplateRequest;
import com.sright.bcard.content.share.service.DataService;
import com.sright.bcard.mini.web.constant.WebUrl;
import com.sright.bcard.user.share.request.TokenParam;
import com.sright.common.response.SrightResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 数据相关controller
 */
@RestController
@RequestMapping()
public class DataController {

    @Autowired
    private DataService dataService;

    /**
     * 点击事件埋点
     * @return
     */
    @PostMapping(WebUrl.Click)
    public SrightResponse countClick(@RequestBody CardTemplateRequest cardTemplateRequest, @RequestAttribute TokenParam tokenParam) {
        return dataService.countClick(cardTemplateRequest.getCardId(), cardTemplateRequest.getType(), tokenParam.getMemberId());
    }

    /**
     * 企业名片详情按钮点击统计（一次访问只计一次）
     * @return
     */
    @GetMapping(WebUrl.ClickOne)
    public SrightResponse clickOne(@RequestParam(value = "cardId") Long cardId,@RequestParam(value = "userId") Long userId) {
        return dataService.countClickOne(cardId,userId);
    }

    /**
     * 统计分享次数
     * @param cardId
     * @param userId
     * @return
     */
    @GetMapping(WebUrl.AddShare)
    public SrightResponse recordShareNum(@RequestParam(value = "cardId") Long cardId, @RequestParam(value = "userId") Long userId) {
        return dataService.recordShareNum(cardId,userId);
    }

    /**
     * 更新最后登录时间
     * @param userId
     * @return
     */
    @GetMapping(WebUrl.UpdateLogin)
    public SrightResponse updateLoginTime(@RequestParam(value = "userId") Long userId) {
        return dataService.updateLoginTime(userId);
    }


}
